<template>
  <div class="edit-container">
    <el-form v-loading="saveLoading" ref="form" :model="form" :rules="rules" label-width="100px" @submit.native.prevent>
      <el-form-item label="缴费金额：" prop="quota">
        <div class="acea-row">
          <el-input-number
              v-model.number="form.quota"
              :min="0"
              :max="9999"
              :step="1"
              class="ml40"
          ></el-input-number>
        </div>
      </el-form-item>
      <el-form-item label="序号：" prop="sort">
        <div class="acea-row">
          <el-input-number
              v-model.number="form.sort"
              :min="0"
              :max="9999"
              :step="1"
              class="ml40"
          ></el-input-number>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button v-loading="saveLoading" element-loading-background="rgba(0, 0, 0, 0.3)" type="primary"
                   @click="handlerSubmit" v-has-permi="['admin:notice:save']">保存
        </el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {amountSave} from "@/api/payment";

export default {
  components: {},
  props: {
    isCreate: {
      type: Number,
      required: true
    },
    editData: {
      type: Object,
      default: () => {
        return {rules: []}
      }
    },
  },
  data() {
    return {
      form: {
        id: null,
        quota: 0,
        sort: 0,
      },
      rules: {
        quota: [{required: true, message: '请上填写金额', trigger: ['blur']}],
      },
      saveLoading: false,
      formLoading: false,
    }
  },
  mounted() {
    if (this.isCreate === 1) {
      this.getDetail();
    }
  },
  methods: {
    getDetail() {
      this.form = this.editData
    },
    handlerSubmit() {
      if (this.saveLoading) {
        return
      }
      this.$refs.form.validate(valid => {
        if (!valid) return;
        this.saveLoading = true;
        console.log(this.form)
        amountSave(this.form).then(() => {
          this.$message.success('保存成功');
          this.close();
        }).finally(() => {
          this.saveLoading = false
        })
      })
    },
    close() {
      this.$emit('hideEditDialog');
    },
  }
}
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
